home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Magazine / GraphicsCards / StormMesa / src / FX / fxlines.c < prev    next >
C/C++ Source or Header  |  1999-02-04  |  6KB  |  233 lines

  1. /* -*- mode: C; tab-width:8;  -*-
  2.  
  3.              fxlines.c - 3Dfx VooDoo line functions 
  4. */
  5.  
  6. /*
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Library General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Library General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Library General Public
  18.  * License along with this library; if not, write to the Free
  19.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  *
  21.  * See the file fxapi.c for more informations about authors
  22.  *
  23.  */
  24.  
  25. #if defined(FX)
  26.  
  27. #include "fxdrv.h"
  28.  
  29. /************************************************************************/
  30. /************************* Lines functions ******************************/
  31. /************************************************************************/
  32.  
  33. #define GOURAUD(v) { \
  34.   fxMesa->gWin[(v)].r=(float) VB->Color[(v)][0]; \
  35.   fxMesa->gWin[(v)].g=(float) VB->Color[(v)][1]; \
  36.   fxMesa->gWin[(v)].b=(float) VB->Color[(v)][2]; \
  37.   fxMesa->gWin[(v)].a=(float) VB->Color[(v)][3]; \
  38. }
  39.  
  40. static void fxLineSmooth(GLcontext *ctx, GLuint v1, GLuint v2, GLuint pv)
  41. {
  42.   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
  43.  
  44.   grDrawLine(&fxMesa->gWin[v1],&fxMesa->gWin[v2]);
  45. }
  46.  
  47. static void fxLineSmoothTwoSide(GLcontext *ctx, GLuint v1, GLuint v2, GLuint pv)
  48. {
  49.   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
  50.   struct vertex_buffer *VB=ctx->VB;
  51.  
  52.   GOURAUD(v1); 
  53.   GOURAUD(v2); 
  54.  
  55.   grDrawLine(&fxMesa->gWin[v1],&fxMesa->gWin[v2]);
  56. }
  57.  
  58. static void fxLineFlat(GLcontext *ctx, GLuint v1, GLuint v2, GLuint pv)
  59. {
  60.   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
  61.   GLubyte *Color=ctx->VB->Color[pv];
  62.  
  63.   grConstantColorValue(FXCOLOR(Color[0], Color[1], Color[2], Color[3]));
  64.  
  65.   grDrawLine(&fxMesa->gWin[v1],&fxMesa->gWin[v2]);
  66. }
  67.  
  68. /************************************************************************/
  69.  
  70. static void fxLineSmoothFrontBack(GLcontext *ctx, GLuint v1,
  71.                   GLuint v2, GLuint pv)
  72. {
  73.   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
  74.  
  75.   if(ctx->Color.ColorMask)
  76.     grColorMask(FXTRUE,FXFALSE);
  77.   else
  78.     grColorMask(FXFALSE,FXFALSE);
  79.   grDepthMask(FXFALSE);
  80.   grRenderBuffer(GR_BUFFER_BACKBUFFER);
  81.   grDrawLine(&fxMesa->gWin[v1],&fxMesa->gWin[v2]);
  82.  
  83.   if(ctx->Color.ColorMask)
  84.     grColorMask(FXTRUE,fxMesa->haveAlphaBuffer ? FXTRUE : FXFALSE);
  85.   else
  86.     grColorMask(FXFALSE,FXFALSE);
  87.   if(ctx->Depth.Mask)
  88.     grDepthMask(FXTRUE);
  89.   grRenderBuffer(GR_BUFFER_FRONTBUFFER);
  90.   grDrawLine(&fxMesa->gWin[v1],&fxMesa->gWin[v2]);
  91. }
  92.  
  93. static void fxLineSmoothTwoSideFrontBack(GLcontext *ctx, GLuint v1,
  94.                      GLuint v2, GLuint pv)
  95. {
  96.   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
  97.   struct vertex_buffer *VB=ctx->VB;
  98.  
  99.   GOURAUD(v1); 
  100.   GOURAUD(v2); 
  101.  
  102.   if(ctx->Color.ColorMask)
  103.     grColorMask(FXTRUE,FXFALSE);
  104.   else
  105.     grColorMask(FXFALSE,FXFALSE);
  106.   grDepthMask(FXFALSE);
  107.   grRenderBuffer(GR_BUFFER_BACKBUFFER);
  108.   grDrawLine(&fxMesa->gWin[v1],&fxMesa->gWin[v2]);
  109.  
  110.   if(ctx->Color.ColorMask)
  111.     grColorMask(FXTRUE,fxMesa->haveAlphaBuffer ? FXTRUE : FXFALSE);
  112.   else
  113.     grColorMask(FXFALSE,FXFALSE);
  114.   if(ctx->Depth.Mask)
  115.     grDepthMask(FXTRUE);
  116.   grRenderBuffer(GR_BUFFER_FRONTBUFFER);
  117.   grDrawLine(&fxMesa->gWin[v1],&fxMesa->gWin[v2]);
  118. }
  119.  
  120. static void fxLineFlatFrontBack(GLcontext *ctx, GLuint v1,
  121.                 GLuint v2, GLuint pv)
  122. {
  123.   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
  124.   GLubyte *Color=ctx->VB->Color[pv];
  125.  
  126.   grConstantColorValue(FXCOLOR(Color[0], Color[1], Color[2], Color[3]));
  127.  
  128.   if(ctx->Color.ColorMask)
  129.     grColorMask(FXTRUE,FXFALSE);
  130.   else
  131.     grColorMask(FXFALSE,FXFALSE);
  132.   grDepthMask(FXFALSE);
  133.   grRenderBuffer(GR_BUFFER_BACKBUFFER);
  134.   grDrawLine(&fxMesa->gWin[v1],&fxMesa->gWin[v2]);
  135.  
  136.   if(ctx->Color.ColorMask)
  137.     grColorMask(FXTRUE,fxMesa->haveAlphaBuffer ? FXTRUE : FXFALSE);
  138.   else
  139.     grColorMask(FXFALSE,FXFALSE);
  140.   if(ctx->Depth.Mask)
  141.     grDepthMask(FXTRUE);
  142.   grRenderBuffer(GR_BUFFER_FRONTBUFFER);
  143.   grDrawLine(&fxMesa->gWin[v1],&fxMesa->gWin[v2]);
  144. }
  145.  
  146. /************************************************************************/
  147.  
  148. static void fxAALineSmooth(GLcontext *ctx, GLuint v1, GLuint v2, GLuint pv)
  149. {
  150.   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
  151.  
  152.   grAADrawLine(&fxMesa->gWin[v1],&fxMesa->gWin[v2]);
  153. }
  154.  
  155. static void fxAALineSmoothTwoSide(GLcontext *ctx, GLuint v1, GLuint v2, GLuint pv)
  156. {
  157.   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
  158.   struct vertex_buffer *VB=ctx->VB;
  159.  
  160.   GOURAUD(v1); 
  161.   GOURAUD(v2); 
  162.  
  163.   grAADrawLine(&fxMesa->gWin[v1],&fxMesa->gWin[v2]);
  164. }
  165.  
  166. static void fxAALineFlat(GLcontext *ctx, GLuint v1, GLuint v2, GLuint pv)
  167. {
  168.   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
  169.   GLubyte *Color=ctx->VB->Color[pv];
  170.  
  171.   grConstantColorValue(FXCOLOR(Color[0],Color[1],
  172.                    Color[2],Color[3]));
  173.  
  174.   fxMesa->gWin[v1].a=fxMesa->gWin[v2].a=(float)Color[3];
  175.  
  176.   grAADrawLine(&fxMesa->gWin[v1],&fxMesa->gWin[v2]);
  177. }
  178.  
  179. /************************************************************************/
  180.  
  181. line_func fxDDChooseLineFunction(GLcontext *ctx)
  182. {
  183.   if((ctx->Line.Width!=1.0f) ||
  184.      (ctx->Line.StippleFlag))
  185.     return NULL;
  186.  
  187.   if(ctx->Line.SmoothFlag) {
  188.     if(ctx->Light.ShadeModel==GL_SMOOTH) {
  189.       if(ctx->Light.Model.TwoSide)
  190.     return fxAALineSmoothTwoSide;
  191.  
  192.       return fxAALineSmooth;
  193.     }
  194.  
  195.     return fxAALineFlat;
  196.   }
  197.  
  198.   if(ctx->RasterMask & FRONT_AND_BACK_BIT) {
  199.     if(ctx->Light.ShadeModel==GL_SMOOTH) {
  200.       if(ctx->Light.Model.TwoSide)
  201.     return fxLineSmoothTwoSideFrontBack;
  202.  
  203.       return fxLineSmoothFrontBack;
  204.     }
  205.  
  206.     return fxLineFlatFrontBack;
  207.   }
  208.  
  209.   if(ctx->Light.ShadeModel==GL_SMOOTH) {
  210.     if(ctx->Light.Model.TwoSide)
  211.       return fxLineSmoothTwoSide;
  212.  
  213.     return fxLineSmooth;
  214.   }
  215.  
  216.   return fxLineFlat;
  217. }
  218.  
  219.  
  220. #else
  221.  
  222.  
  223. /*
  224.  * Need this to provide at least one external definition.
  225.  */
  226.  
  227. int gl_fx_dummy_function_lines(void)
  228. {
  229.   return 0;
  230. }
  231.  
  232. #endif  /* FX */
  233.